<%@ page contentType="text/html;charset=utf-8"%>
<%@ page
	import="java.io.*, java.sql.*, java.util.*, java.text.*, napal.*, util.*"%>
<%@ page import="org.apache.ibatis.*"%>
<%
	request.setCharacterEncoding("utf-8");
%>
<%@ include file="./Header.jsp"%>
		</td>
		</TR>
		<TR HEIGHT="100">
		<td>
		<a href="RentalList_s.jsp" class="btn btn-link btn-small">대여신청<br></a>
>  기자재상세정보<br><br><br>

	<% 
	String cmd = request.getParameter("cmd");
	String str_aid = request.getParameter("str_aid");
	if(str_aid==null){ %>
	<script language=javascript>
				self.window.alert("접근할 수 없습니다.");
				location.href="Main.jsp?";
			</script>
<%}else{
	String selectedCategory = request.getParameter("category");
	String model_id = request.getParameter("model_id");
	String e_sto = request.getParameter("e_sto");
	String mid = request.getParameter("mid");
	
	int aid = Integer.parseInt(str_aid);
	EquipmentDetail r = RentalHome.Detail(aid);
	
	%>
	<input type="hidden" name="category" value="<%=  selectedCategory %>" />
	<table class="table table-bordered">

		<Tr>
			<td>카테고리명</td>
			<Td><%=r.get카테고리명()%></td>
		</tr>
		<tr>
			<td>모델명</td>
			<Td><%=r.get모델명()%></td>
		<tr>
			<td>학과이름</td>
			<Td><%=r.get학과이름()%></td>
		</tr>
		<tr>
			<td>보관사용처</td>
			<td><%=r.get보관사용처()%></td>
		</tr>
		<tr>
			<td>구매날짜</td>
			<td><%=r.get구매날짜()%></td>
		</tr>
		<tr>
			<td>구매금액</td>
			<td><%=r.get구매금액()%></td>
		</tr>
		<tr>
			<td>비고</td>
			<td><%=r.get비고()%></td>
			<form method=post><input type="hidden" name="mid" value=<%= r.get모델번호() %>>
			
		</tr>

	</table>
	<%		if ("예약".equals(cmd)) {
		List<book> b=RentalHome.getbook2(userID);
		if(b.isEmpty()==false){%>
		<script language=javascript>
		self.window.alert("이미 예약중인 기자재가 있습니다.");
		location.href="EquipmentDetail_s.jsp?str_aid=<%=r.get기자재번호()%>&model_id=<%=r.get모델번호()%>";
</script>
	<%}
		else{
		List<book> b2=RentalHome.getbook3(r.get보관사용처(),r.get모델번호());
		
		if(b2.isEmpty()==false){%>
			<script language=javascript>
			self.window.alert("기자재 예약이 꽉 찼습니다.");
			location.href="EquipmentDetail_s.jsp?str_aid=<%=r.get기자재번호()%>&model_id=<%=r.get모델번호()%>";
</script>
		<%}
		else{
		RentalHome.insertbook(userID,r.get보관사용처(),r.get모델번호());%>
		<script language=javascript>
						self.window.alert("기자재를 예약신청하였습니다.");
						location.href="RentalList_s.jsp";
			</script>
		<% 
	}}}
%>

<form onsubmit="return confirm('해당 기자재를 예약신청하시겠습니까?');">
<p align="center">
	<a href="RentalList_s.jsp" name="cmd" class="btn btn-inverse">목록으로</a><%
			int a=r.get모델번호();
			String b=r.get보관사용처();
		
			 for(EM bc : RentalHome.getModelCount(a,b)){
			if(bc.get대여가능수()!=0){
				%><a href="EquipmentRental_s.jsp?str_aid=<%=str_aid %>&e_sto=<%=r.get보관사용처()%>&m_name=<%=r.get모델명()%>&model_id=<%=r.get모델번호()%>" name="cmd" class="btn btn-inverse" value="rental">대여신청</a>

<%
 	}
			%><%
 	else {
 	%>
			<input name="cmd" type="submit" class="btn btn-inverse"  style="width:60" value="예약">
			
			 <%}}
 %> </form>
	<%if ("목록으로".equals(request.getParameter("cmd"))) {
		String selecte = request.getParameter("category");
		}
	%>
</p>
<%} %>
		</td>
		</tr>
		<TR HEIGHT="50">
			<TD><%@ include file="./bottom.jsp"%></TD>
		</TR>
	</TABLE>
</body>
</html>